package org.ms.mconf.sdk.service;

import org.micro.URL;
import org.ms.mconf.sdk.NotifyListener;
import org.ms.mconf.sdk.exception.ConfigException;
import org.ms.mconf.sdk.exception.ConnectException;
import org.ms.mconf.sdk.exception.MicroConfigException;
import org.ms.mconf.sdk.model.MetaMultiDataConfig;

import java.util.List;

/**
 * The Config Service
 *
 * @author lry
 */
public interface IConfigService {

    /**
     * The initialize config center
     *
     * @param url connect URL {@link URL}
     * @throws MicroConfigException Micro Config Exception {@link MicroConfigException}
     */
    void initialize(URL url) throws MicroConfigException;

    /**
     * The subscribe to multiple configurations according to the application
     *
     * @param listener    Notify Listener {@link NotifyListener}
     * @param application application id
     * @param configs     config ids
     * @throws MicroConfigException micro config Exception: {@link ConnectException}, {@link ConfigException}
     */
    void subscribe(NotifyListener<MetaMultiDataConfig> listener, String application, String... configs) throws MicroConfigException;

    /**
     * The unsubscribe to multiple configurations according to the application
     *
     * @param application application id
     * @param configs     config ids
     * @throws MicroConfigException micro config Exception: {@link ConnectException}, {@link ConfigException}
     */
    void unsubscribe(String application, String... configs) throws MicroConfigException;

    /**
     * The pull to multiple configurations according to the application
     *
     * @param application application id
     * @param configs     config ids
     * @return Meta Multi Data Config {@link MetaMultiDataConfig}
     * @throws MicroConfigException micro config Exception: {@link ConnectException}, {@link ConfigException}
     */
    List<MetaMultiDataConfig> pull(String application, String... configs) throws MicroConfigException;

    /**
     * The destroy config center
     *
     * @throws MicroConfigException Micro Config Exception {@link MicroConfigException}
     */
    void destroy() throws MicroConfigException;

}
